package com.ck.shardinggo.converter;

import com.ck.shardinggo.model.PowerperformanceHistory;
import com.ck.shardinggo.utils.SnowFlakeGenerator;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Author yd
 * @Date 2018/12/21 17:26
 */
public class PowerPerformanceHistoryConvertor {

    public static PowerperformanceHistory generrator(){
        Map<Integer,Integer> deviceidMap = new HashMap<>();
        deviceidMap.put(1,755000025);
        deviceidMap.put(2,755000038);
        deviceidMap.put(3,755000030);
        deviceidMap.put(4,755000043);
        deviceidMap.put(5,755000036);
        deviceidMap.put(6,755000034);
        deviceidMap.put(7,755000032);
        deviceidMap.put(8,755000016);
        deviceidMap.put(9,755000040);
        deviceidMap.put(0,755000002);
        deviceidMap.put(10,755000003);
        deviceidMap.put(11,755000004);
        deviceidMap.put(12,755000005);
        deviceidMap.put(13,755000006);
        deviceidMap.put(14,755000007);
        deviceidMap.put(15,755000008);
        deviceidMap.put(16,755000009);
        deviceidMap.put(17,755000010);

        Random rm= new Random();

        PowerperformanceHistory powerperformanceHistory = new PowerperformanceHistory();
        //powerperformanceHistory.setId(new SnowFlakeGenerator.Factory().create(5, 5).nextId());
       powerperformanceHistory.setId(Long.parseLong(generate4VerifiCode(5)));
        System.out.println(Long.parseLong(generate4VerifiCode(10)));
        powerperformanceHistory.setOriginaldeviceid(deviceidMap.get(rm.nextInt(16)));
        powerperformanceHistory.setSignalid(Integer.parseInt(generate4VerifiCode(7)));
        //powerperformanceHistory.setStringvalue(generate4VerifiCode(2));
        powerperformanceHistory.setTime(new Date());
        return powerperformanceHistory;
    }

    /**
     * 产生n位的id
     * @param num
     * @return
     */
    public static String generate4VerifiCode(Integer num){
        String str="0123456789";
        StringBuilder sb=new StringBuilder(num);
        for(int i=0;i<num;i++)
        {
            char ch=str.charAt(new Random().nextInt(str.length()));
            sb.append(ch);
        }
        return sb.toString();
    }
}
